import defaultSettings from './defaultSettings'; // https://umijs.org/config/

import slash from 'slash2';
import themePluginConfig from './themePluginConfig';

const {pwa} = defaultSettings; // preview.pro.ant.design only do not use in your production ;
// preview.pro.ant.design 专用环境变量，请不要在你的项目中使用它。

const {ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION} = process.env;
const isAntDesignProPreview = ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site';


const plugins = [
  [
    'umi-plugin-react',
    {
      antd: true,
      dva: {
        hmr: true,
      },
      locale: {
        // default false
        enable: true,
        // default zh-CN
        default: 'zh-CN',
        // default true, when it is true, will use `navigator.language` overwrite default
        baseNavigator: true,
      },
      dynamicImport: {
        loadingComponent: './components/PageLoading/index',
        webpackChunkName: true,
        level: 3,
      },
      pwa: pwa
        ? {
          workboxPluginMode: 'InjectManifest',
          workboxOptions: {
            importWorkboxFrom: 'local',
          },
        }
        : false, // default close dll, because issue https://github.com/ant-design/ant-design-pro/issues/4665
      // dll features https://webpack.js.org/plugins/dll-plugin/
      // dll: {
      //   include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'],
      //   exclude: ['@babel/runtime', 'netlify-lambda'],
      // },
    },
  ],
  [
    'umi-plugin-pro-block',
    {
      moveMock: false,
      moveService: false,
      modifyRequest: true,
      autoAddMenu: true,
    },
  ],
];

if (isAntDesignProPreview) {
  // 针对 preview.pro.ant.design 的 GA 统计代码
  plugins.push([
    'umi-plugin-ga',
    {
      code: 'UA-72788897-6',
    },
  ]);
  plugins.push(['umi-plugin-antd-theme', themePluginConfig]);
}

export default {
  plugins,
  hash: true,
  targets: {
    ie: 11,
  },
  // umi routes: https://umijs.org/zh/guide/router.html
  routes: [
    {
      path: '/user',
      component: '../layouts/UserLayout',
      routes: [
        {
          name: 'login',
          path: '/user/login',
          component: './user/login',
        },
      ],
    },
    {
      path: '/',
      component: '../layouts/SecurityLayout',
      routes: [
        {
          path: '/',
          component: '../layouts/BasicLayout',
          authority: ['admin', 'user'],
          routes: [
            {
              path: '/',
              redirect: '/fengxiang',
            },
            {
              name: 'location',
              icon: 'smile',
              path: '/fengxiang/location',
              component: './FengXiang/location',
              hideInMenu: 'true',
            },
            {
              name: 'analysis',
              icon: 'smile',
              path: '/fengxiang/analysis',
              component: './FengXiang/analysis',
              hideInMenu: 'true',
            },
            {
              name: 'main',
              icon: 'smile',
              path: '/hanfan/main',
              component: './HanFan/index',
              hideInMenu: 'true',
            },
            {
              name: 'yacha',
              icon: 'smile',
              path: '/hanfan/yacha',
              component: './YaCha/index',
              hideInMenu: 'true',
            },
            {
              name: 'hanfan',
              path: '/hanfan',
              icon: 'RocketOutlined',
              children: [
                {
                  name: 'location',
                  path: '/hanfan/main',
                  icon: 'user',
                },
                {
                  name: 'yacha',
                  path: '/hanfan/yacha',
                  icon: 'user',
                }
              ],
            },
            {
              name: 'shaojie',
              path: '/fengxiang',
              icon: 'RocketOutlined',
              children: [
                {
                  name: 'location',
                  path: '/fengxiang/location',
                  icon: 'user',
                },
                // {
                //   name: 'analysis',
                //   path: '/fengxiang/analysis',
                //   icon: 'user',
                // },
              ],
            },
            {
              name: 'main',
              icon: 'smile',
              path: '/gaolu/main',
              hideInMenu: 'true',
              component: './GaoLu/components/Main',
            },
            {
              name: 'paramStatus',
              icon: 'smile',
              path: '/gaolu/paramStatus',
              hideInMenu: 'true',
              component: './GaoLu/components/ParamStatus',
            },
            {
              name: 'scoreTrend',
              icon: 'smile',
              path: '/gaolu/scoreTrend',
              hideInMenu: 'true',
              component: './GaoLu/components/ScoreTrend/wrapper',
            },
            {
              name: 'coreData',
              icon: 'smile',
              path: '/gaolu/coreData',
              hideInMenu: 'true',
              component: './GaoLu/components/CoreData/wrapper',
            },
            {
              name: 'banzu',
              icon: 'smile',
              path: '/gaolu/banzu',
              hideInMenu: 'true',
              component: './GaoLu/components/Banzu',
            },
            {
              name: 'historyExplore',
              icon: 'smile',
              path: '/gaolu/history',
              hideInMenu: 'true',
              component: './GaoLu/components/History',
            },
            {
              name: 'gaoluRuleDefine',
              icon: 'smile',
              path: '/gaolu/ruleDefine',
              hideInMenu: 'true',
              component: './GaoLu/components/Rule',
            },
            {
              name: 'dashboard',
              icon: 'smile',
              path: '/visible/dashboard',
              hideInMenu: 'true',
              component: './Superset/components/Dashboard',
            },
            {
              name: 'chart',
              icon: 'smile',
              path: '/visible/chart',
              hideInMenu: 'true',
              component: './Superset/components/Chart',
            },
            {
              name: 'gaolu',
              icon: 'smile',
              path: '/gaolu',
              children: [{
                name: 'main',
                path: '/gaolu/main',
                icon: 'user',
              }, {
                name: 'paramStatus',
                path: '/gaolu/paramStatus',
                icon: 'user',
              }, {
                name: 'coreData',
                path: '/gaolu/coreData',
                icon: 'user',
              }, {
                name: 'banzu',
                path: '/gaolu/banzu',
                icon: 'user',
              }, {
                name: 'scoreTrend',
                path: '/gaolu/scoreTrend',
                icon: 'user',
              },
                {
                  name: 'historyExplore',
                  path: '/gaolu/history',
                  icon: 'user'
                },
                {
                  name: 'gaoluRuleDefine',
                  path: '/gaolu/ruleDefine',
                  icon: 'user',
                }
              ]
            },
            {
              name: 'gaoluDiagnose',
              icon: 'smile',
              path: '/gaoluDiagnose',
              children: [{
                name: 'main',
                path: '/gaoluDiagnose/main',
                icon: 'user',
              }, {
                name: 'ruleDefine',
                path: '/gaoluDiagnose/ruleDefine',
                icon: 'user',
              }]
            },
            {
              name: 'main',
              icon: 'smile',
              path: '/gaoluDiagnose/main',
              hideInMenu: 'true',
              component: './GaoLuDiagnose/components/Main',
            },
            {
              name: 'ruleDefine',
              icon: 'smile',
              path: '/gaoluDiagnose/ruleDefine',
              hideInMenu: 'true',
              component: './GaoLuDiagnose/components/RuleDefine',
            },

            {
              component: './404',
            },
          ],
        },
        {
          component: './404',
        },
      ],
    },
    {
      component: './404',
    },
  ],
  // Theme for antd: https://ant.design/docs/react/customize-theme-cn
  theme: {
    // ...darkTheme,
    'menu-dark-bg': '#43464c',
    'menu-dark-submenu-bg': '#32353a',
    'layout-sider-background': '#43464c',
    'layout-body-background': '#efeff4',
  },
  define: {
    ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION:
      ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION || '', // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量，请不要在你的项目中使用它。
    proxy: {
      '/api': {
        target: 'http://localhost:8192',
        pathRewrite: {'^/api': ''},
        changeOrigin: true
      }
    }
  },
  ignoreMomentLocale: true,
  lessLoaderOptions: {
    javascriptEnabled: true,
  },
  disableRedirectHoist: true,
  cssLoaderOptions: {
    modules: true,
    getLocalIdent: (context, _, localName) => {
      if (
        context.resourcePath.includes('node_modules') ||
        context.resourcePath.includes('ant.design.pro.less') ||
        context.resourcePath.includes('global.less')
      ) {
        return localName;
      }

      const match = context.resourcePath.match(/src(.*)/);

      if (match && match[1]) {
        const antdProPath = match[1].replace('.less', '');
        const arr = slash(antdProPath)
          .split('/')
          .map(a => a.replace(/([A-Z])/g, '-$1'))
          .map(a => a.toLowerCase());
        return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
      }

      return localName;
    },
  },
  manifest: {
    basePath: '/',
  },
  // chainWebpack: webpackPlugin,
  proxy: {
    '/api': {
      // target: 'http://121.199.57.100:8080',
      target: "http://localhost:8088",
      changeOrigin: true,
      pathRewrite: {
        '^/api': '/api/v1',
      },
    },
  },
};
